package kr.hkit.androidcomplete03.ch29;

import kr.hkit.androidcomplete03.R;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

public class NapAlam extends Activity {
	static final int NAPNOTI = 1;
	NotificationManager mNotiManager;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.ch29_napalam);
		mNotiManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
	}

	public void mOnClick(View v) {
		Toast.makeText(NapAlam.this, "안녕히 주무세요", 0).show();
		v.postDelayed(new Runnable() {
			public void run() {
				Intent intent = new Intent(NapAlam.this, NapEnd.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				PendingIntent content = PendingIntent.getActivity(NapAlam.this,
						0, intent, 0);

				Notification noti = new Notification.Builder(NapAlam.this)
						.setTicker("일어나세요")
						.setContentTitle("기상 시간")
						.setContentText("일어나! 일할 시간이야.")
						.setSubText("일을 해야 돈을 벌고 돈을 벌어야 밥먹고 살지!!")
						.setSmallIcon(R.drawable.mingyeong1)
						.setLargeIcon(
								BitmapFactory.decodeResource(getResources(),
										R.drawable.mingyeong1))
						.setContentIntent(content).build();

				mNotiManager.notify(NapAlam.NAPNOTI, noti);
			}
		}, 5 * 1000);
	}
}
